package com.bjpowernode.controller;

import com.bjpowernode.entity.TClue;
import com.bjpowernode.result.Result;
import com.bjpowernode.service.ClueService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import lombok.Getter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class ClueController {

    @Resource
    private ClueService clueService;

    @GetMapping("/api/clues")
    public Result getClueByPage(Integer current) {
        PageInfo<TClue> pageInfo = clueService.getClueByPage(current);

        return Result.OK(pageInfo);
    }


    /**
     * 导入线索excel
     * @param excelFile 参数名要与表单中的name一致
     */
    @RequestMapping("api/importExcel")
    public Result importExcel(MultipartFile excelFile) throws IOException {
        clueService.importExcel(excelFile.getInputStream());
        return Result.OK();
    }

    /**
     * 根据线索id查询线索详情
     */
    @GetMapping("/api/clue/{id}")
    public Result getClueById(@PathVariable Integer id) {
        TClue clue = clueService.getClueById(id);
        return Result.OK(clue);
    }
}
